package com.mingnew.ecache.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author : lk
 * @date 2021/5/2 11:47
 **/
@Data
@AllArgsConstructor
public class Result<T> {


    private Integer code;
    private String message;
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private T data;


    private Result() {
    }
    public static <T> Result<T> success() {
        return of(StatueEnum.SUCCESS.getCode(), StatueEnum.SUCCESS.getMessage(),null);
    }

    public static <T> Result<T> success(T data) {
        return of(StatueEnum.SUCCESS.getCode(), StatueEnum.SUCCESS.getMessage(), data);
    }

    public static <T> Result<T> of(Integer code, String message, T data) {
        return new Result<>(code, message, data);
    }

    public static <T> Result<T> failed(Integer code, String message) {
        return of(code, message, null);
    }

    public static <T> Result<T> failed() {
        return of(StatueEnum.ERROR.getCode(), StatueEnum.ERROR.getMessage(), null);
    }


}
